package middlewares

import (
	"gin-study/app/services"
	"gin-study/pkg/helper"
	"gin-study/pkg/log"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func RequestLog() gin.HandlerFunc {
	return helper.WarpHandle(func(c *gin.Context) interface{} {
		c.Next()

		res := services.Ctx.GetResponse(c)
		body := make([]byte, 0)
		reader := c.Request.Body
		reader.Read(body)

		log.Zap.Info("request",
			zap.String("uri", c.Request.RequestURI),
			zap.Any("body", body),
			zap.Any("res", res),
		)

		return nil
	})

}
